//
//  UIButton+Extension.swift
//  54_Weibo(swift)
//
//  Created by 梦然 张 on 16/4/6.
//  Copyright © 2016年 梦然 张. All rights reserved.
//

import UIKit

extension UIButton{
    
    /// 设置button的图片、背景图片 的便利构造方法
    ///
    /// - parameter imageName:     图片名称
    /// - parameter backImageName: 北京图片名称
    ///
    /// - returns:
    convenience init(imageName: String, backImageName: String){
        self.init()
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        sizeToFit()
    }
    
    /// 设置button的便利构造方法
    ///
    /// - parameter title:       名称
    /// - parameter color:       字体颜色
    /// - parameter fontSize:    字体大小
    /// - parameter backImgName: 背景图
    ///
    /// - returns: 
    convenience init(title: String, color: UIColor, fontSize: CGFloat, backImgName: String){
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setBackgroundImage(UIImage(named: backImgName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImgName + "_highlighted"), forState: .Highlighted)
    }
}
